{* $Id: common_fav.html 22490 2013-04-08 07:43:02Z weisd $ *}
{if in_array($user_id, $list)}
  {if $params['fav_type'] == 2}
    <a class="favBtn hasFav set-collected set-options" href="javascript:;" ><span>已收藏</span></a>
  {else}
    <a class="favBtn hasFav curr" href="javascript:void(0);"><i class="icon-collect"></i><span>已收藏</span></a>
  {/if}
{else}
  {if $params['fav_type'] == 2}
    <a class="favBtn set-collect set-options" href="javascript:;" ><span>收藏</span></a>
  {else}
    <a class="favBtn" href="javascript:void(0);"><i class="icon-collect"></i><span>收藏</span></a>
  {/if}
{/if}
<script type="text/javascript">
$(function(){
  var resName = "{$params['res_name']}";
  var resId = "{$params['res_id']}";
  
  $(".favBtn").click(function(){
  console.log(resName);
  console.log(resId);
    var thisObj = $(this);
    if (resName == '' || resId == '') {
      showMsg('请选择要收藏的资源','err');
      return false;
    }
    
    var url = siteUrl;
    if (thisObj.hasClass('hasFav')) {
      url += '/fav/delete'
    } else {
      url += '/fav/save'
    }
    
    $.post(url, { 'res_name':resName, 'res_id':resId }, function(json){
        if (json.info != 'ok') {
            showMsg(json.info, 'err');
            return false;
        }
        
        if (thisObj.hasClass('hasFav')) {
          thisObj.removeClass('hasFav').removeClass('curr').children('span').text('收藏');
        } else {
          thisObj.addClass('hasFav').addClass('curr').children('span').text('已收藏');
        }
        if (thisObj.hasClass('set-collected')) {
          thisObj.removeClass('set-collected').addClass('set-collect');
        } else {
          thisObj.removeClass('set-collect').addClass('set-collected');
        }
        
        //var num = parseInt(thisObj.next(".favNum").text()) + 1;
        //thisObj.addClass("hasFav").removeClass("favBtn").text('已收藏').next(".favNum").text(num);
        //thisObj.unbind('click');
    }, 'json');
  });
});
</script>